<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use think\Db;
use app\admin\model\QuestionData as DataModel;
use app\common\library\Excel;
use think\Session;

/**
 * 
 *
 * @icon fa fa-circle-o
 */
class QuestionData extends Backend
{

    /**
     * DataModel
     * @var \app\admin\model\DataModel
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new DataModel;

    }

    public function import()
    {
        parent::import();
    }

     /**
     * 查看
     */
    public function index()
    {
        //当前是否为关联查询
        $this->relationSearch = false;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $obj = $this->model->where($where);
            $admin = Session::get('admin');
            if($admin['affiliated_center_id']!= 0){
                $arr_area = explode(',',$admin['affiliated_center_id']);
                $obj->where(['a.area_one_id'=>['in',$arr_area]]);
            }
             
            $list = $obj
                    ->alias('d')
                    ->field('d.id,d.create_time,d.center_id,a.title,a.area_one_id')
                    ->join('ftu_activity a','d.center_id = a.id','left')
                    // ->join('ftu_child_q_format f','d.qid = f.qid','left')
 
                    ->where('d.delete_time','=',0)
                    ->where('d.center_id','>',0)
                    // ->where('uid','=',$uid)
                    ->order($sort, $order)
                    ->paginate($limit);

            


            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        // $data = QService::getQuestionnaireClassList();
        // $mode = QEnum::getMarkShowMode();
        // return $this->fetch('list', ['data' => $data, 'mode' => $mode]);
        return $this->view->fetch();
    }

   
    public function user_list($ids)
    {
         $this->assignconfig("ids", $ids);
        //当前是否为关联查询
        $this->relationSearch = false;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $obj = $this->model->where($where);
            $admin = Session::get('admin');
            // if($admin['affiliated_center_id']!= 0){
            //     $arr_area = explode(',',$admin['affiliated_center_id']);
            //     $obj->where(['a.area_one_id'=>['in',$arr_area]]);
            // }
             
            $list = $obj
                    ->alias('d')
                    ->field('d.id,d.create_time,a.name as title')
                    ->join('child_q_format a','a.id = d.qid','left')
                
 
                    ->where('d.delete_time','=',0)
                  
                     ->where('d.uid','=',$ids)
                    ->order($sort, $order)
                    ->paginate($limit);

            


            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
 
        return $this->view->fetch();
    }


}